//
//  SettingTableViewController.m
//  ForeverLove
//
//  Created by lanou3g on 15/11/12.
//  Copyright © 2015年 文萱竹. All rights reserved.
//

#import "SettingTableViewController.h"

#import "PersonalDataTableViewController.h"

#import "SDImageCache.h"

@interface SettingTableViewController ()

@property (nonatomic, strong) NSMutableArray *dataArray;
- (IBAction)barAction:(UIBarButtonItem *)sender;

@end

@implementation SettingTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    NSArray *arr1 = @[@"个人资料"];
    NSArray *arr2 = @[@"清除缓存"];
    NSArray *arr3 = @[@"帮助中心"];
    NSArray *arr4 = @[@"关于我们"];
    NSArray *arr5 = @[@"退出登录"];
    self.dataArray = [NSMutableArray arrayWithObjects:arr1, arr2, arr3, arr4, arr5, nil];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"setCELL"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.dataArray[section] count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"setCELL" forIndexPath:indexPath];
    
    cell.imageView.image= [UIImage imageNamed:@"xin.png"];
    cell.textLabel.text = self.dataArray[indexPath.section][indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

        UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        PersonalDataTableViewController *personVC = [story instantiateViewControllerWithIdentifier:@"person"];

        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];

    UILabel *label = [[UILabel alloc] init];
    
    switch (indexPath.section) {
        case 0:
            [self.navigationController pushViewController:personVC animated:YES];
            break;
        case 1:
        {
            
        }
            break;
        case 2:
        {
            label.frame = CGRectMake(0, 370, self.view.frame.size.width, 30);
            [self.view addSubview:label];
            label.text = @"😊感谢您使用我们的产品哦😊";
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor cyanColor];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [UIView animateWithDuration:2.0f animations:^{
                    label.alpha = 0;
                } completion:^(BOOL finished) {
                    label.hidden = YES;
                }];
            });
        }
            break;
        case 3:
        {
            label.frame = CGRectMake(0, 400, self.view.frame.size.width, 30);
            [self.view addSubview:label];
            label.text = @"😊本应用纯属巧合, 如有雷同, 纯属虚构😊";
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor cyanColor];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [UIView animateWithDuration:2.0f animations:^{
                    label.alpha = 0;
                } completion:^(BOOL finished) {
                    label.hidden = YES;
                }];
            });
        }
            break;
        case 4:
            if ([ud boolForKey:@"isLogin"]) {
                [ud setBool:YES forKey:@"isLogin"];
            }else{
                label.frame = CGRectMake(0, 430, self.view.frame.size.width, 30);
                [self.view addSubview:label];
                label.text = @"😊您还有没有登录哦😊";
                label.textAlignment = NSTextAlignmentCenter;
                label.textColor = [UIColor cyanColor];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [UIView animateWithDuration:0.6f animations:^{
                        label.alpha = 0;
                    } completion:^(BOOL finished) {
                        label.hidden = YES;
                    }];
                });
            }
 
            break;
        default:
            break;
    }
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)barAction:(UIBarButtonItem *)sender {
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
@end
